<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    request.setAttribute("basePath", basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp" %>
<%@ include file="/resources/js/wechat/_wechatui.jsp" %>
<!DOCTYPE>
<html>
<head>
    <title>微信</title>
    <script src="${basePath}resources/js/easyui/Jquery-md5.js"></script>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<%--<header class='login_header'>
    <a href="javascript:history.go(-1);" class="top_fh">微信</a>
</header>--%>
<!-- header end -->

<div class="page login_page">
    <div class="login_inner">
        <form id="myForm" name="myForm">
            <div class="login_tx"><img src="${basePath}resources/js/wechat/images/login_tx.png" alt=""></div>
            <!-- 错误提示 -->
            <div class="loginPoint"></div>
            <div class="lgin_form">
                <div class='lg_zh'><input id="username" name="username" type="text" placeholder="请输入用户名"></div>
                <div class='lg_ps'>
                    <input id="password" type="password" placeholder="请输入密码">
                    <input type="hidden" id="loginpassword" name="password"/>
                    <input type="hidden" id="openId" name="openId"/>

                </div>
                <div class='lg_yzm'><input class="loginyzm" id="valid" name="vildCode" type="text" placeholder="请输入验证码"><img
                        id="captchaImage" src="${basePath}authCode" alt=""
                        onclick="chageCode()"></div>
                <div class="lg_button"><input type="button" value="登录" class="login_button" style="font-size:1rem;"
                                              onClick="login()"></div>
                <div class="lg_qt"><a href="${basePath}wechat/login/showView">忘记密码</a><a
                        href="${basePath}wechat/register/gotoRegister">还没有帐号？立即注册>></a></div>
            </div>
        </form>
    </div>
    <div class="footer_bz">游艺云</div>
</div>
</body>
</html>

<script>
    $("#openId").val(getCookie('openid'));
    var regUser = /^\w{5,20}$/;
    var regPassword = /^\w{6,18}$/;
    var username = "";
    var password = "";
    var valid = "";
    function chageCode() {
        $('#captchaImage').attr('src', '${basePath}authCode?abc=' + Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
    }
    ;
    $(".page").yanZheng();
    function login() {
        username = $("#username").val();
        password = $("#password").val();
        vaild = $("#valid").val();
       console.log(createPassword(password, password));
        if (username == null || username == '') {
            $(".loginPoint").text("用户名不能为空");
            //alert("用户名不能为空");
        } else if (password == null || password == '') {
            $(".loginPoint").text("密码不能为空");
            //alert("密码不能为空");
        } else if (vaild == null || vaild == '') {
            $(".loginPoint").text("验证码不能为空");
            //alert("验证码不能为空");
        } else if (regUser.test(username) && regPassword.test(password) && vaild != "") {
            var begin = new Date().getMilliseconds();
            console.log("开始登录" + begin);
            $("#loginpassword").val(createPassword(password, password));
            $.ajax({
                url: '${basePath}wechat/login/signin',
                type: 'POST',
                data: $("#myForm").serialize(),
                error: function (response) {
                    if(response.status == 0 && response.statusText == "error"){
                        alert("系统提示：网络异常，请检查您的网络是否正常。");
                    }else{
                        ViewHelper.func.ajaxWechatErrorMessage(response);
                    }
                },
                success: function (ret) {
                    if (ret.result) {
                        <%--window.location = "${basePath}wechat/income/accounts/mainView";--%>
                        console.log("开始登录" + new Date().getMilliseconds() - begin +"毫秒" );
                        window.location = "${basePath}wechat/login/goView";
                    } else {
                        //alert(ret.info);
                        $(".loginPoint").text(ret.info);
                    }
                }
            });
        }

    }
    ;
</script>